package controllers;

import beans.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import services.impl.UserServicesImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserServicesImpl usi;

    @RequestMapping("/user")
    public List user() {
        List<User> list=usi.selectList();
        return list;
    }

    @RequestMapping("/createuser")
    public String createUser(@RequestBody User user) {
        usi.insertSelective(user);
        return null;
    }
    //用户授权信息
    @RequestMapping("/tgauser")
    public String tgaUser() {
        return "index";
    }

    @RequestMapping("/edituser")
    public String editUser(@RequestBody User user) {
        usi.updateByPrimaryKeySelective(user);
        return null;
    }

    @RequestMapping("/editpassword")
    public String editPassword(User user) {
        usi.updateByPrimaryKeySelective(user);
        return null;
    }

    @RequestMapping("/detailsuser")
    public User detailsUser(HttpServletRequest request) {
        int i=Integer.parseInt(request.getParameter("userNumber"));
        User user= usi.selectByPrimaryKey(i);
        return user;
    }

    @RequestMapping("/searchuser")
    public List<User> searchUser(@RequestBody Map<String,String> request) {
        String select=request.get("selectText");
        String input=request.get("inputText");
        List<User> list=usi.selectSelective(select,input);
        return list;
    }

    @RequestMapping("/deleteuser")
    public String deleteUser(HttpServletRequest request) {
        int i=Integer.parseInt(request.getParameter("userNumber"));
        usi.deleteByPrimaryKey(i);
        return null;
    }

}
